var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
//引入cookie-session
var cookieSession = require('cookie-session')

var apiRouter = require('./routes/api');

var app = express();

//解决所有接口跨域
//引入： const cors = require('cors')
//app.use(cors())

//设置cookie-session 存储名字，加密方式
app.use(cookieSession({
    name:'token',
    keys:['giggoooooo']
}))

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/api', apiRouter);

module.exports = app;
